﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace VietImageSoftware
{
    class ReadXMLHelper
    {
        private String username;

        public String Username
        {
            get { return username; }
            set { username = value; }
        }

        private String imageAuthor;

        public String ImageAuthor
        {
            get { return imageAuthor; }
            set { imageAuthor = value; }
        }

        private String categoryAuthor;

        public String CategoryAuthor
        {
            get { return categoryAuthor; }
            set { categoryAuthor = value; }
        }

        private int language;

        public int Language
        {
            get { return language; }
            set { language = value; }
        }

        public ReadXMLHelper()
        {
            username = "";
            imageAuthor = "";
            categoryAuthor = "";
            language = 1;
        }

        public bool ReadXML()
        {
            try
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load("XMLRecentActivity.xml");

                XmlNode node = xdoc.DocumentElement;

                username = node.ChildNodes[0].InnerText;
                imageAuthor = node.ChildNodes[1].InnerText;
                categoryAuthor = node.ChildNodes[2].InnerText;
                language = int.Parse(node.ChildNodes[3].InnerText);

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        public bool WriteXML()
        {
            try
            {
                XmlDocument xdoc = new XmlDocument();
                xdoc.Load("XMLRecentActivity.xml");

                XmlNode node = xdoc.DocumentElement;

                node.ChildNodes[0].InnerText = username;
                node.ChildNodes[1].InnerText = imageAuthor;
                node.ChildNodes[2].InnerText = categoryAuthor;
                node.ChildNodes[3].InnerText = language.ToString();

                xdoc.Save("XMLRecentActivity.xml");

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
